<?php
/*
	$Id: checkout.php 2 2011-02-17 13:35:25Z akausch $

	Fixed by commerce:SEO (c) 2010
	Author - Daniel Siekiera

*/

class Checkout {

	function getDSG($which) {
		switch ($which) {
			case 'text' :
				if (DISPLAY_DATENSCHUTZ_ON_CHECKOUT == 'true') {
					if (GROUP_CHECK == 'true') {
						$group_check = "and group_ids LIKE '%c_" . $_SESSION['customers_status']['customers_status_id'] . "_group%'";
					}
					$shop_content_query = xtc_db_query("SELECT
															content_title,
															content_heading,
															content_text,
															content_file
														FROM
															" . TABLE_CONTENT_MANAGER . "
														WHERE
															content_group='2' " . $group_check . "
														AND
															languages_id='" . $_SESSION['languages_id'] . "'");
					$shop_content_data = xtc_db_fetch_array($shop_content_query);
					if ($shop_content_data['content_file'] != '') {
						if($shop_content_data['content_file'] == 'janolaw_datenschutz.php') {
							include_once(DIR_FS_INC.'janolaw.inc.php');
							$conditions = JanolawContent('datenschutzerklaerung', 'txt');
						} else
							$conditions = '<iframe src="' . DIR_WS_CATALOG . 'media/content/' . $shop_content_data['content_file'] . '" width="100%" height="300"></iframe>';
					} else {
						$conditions = '<textarea name="blabla" cols="60" rows="10" readonly="readonly">' . strip_tags(str_replace('<br />', "\n", $shop_content_data['content_text'])) . '</textarea>';
					}
					return $conditions;
				}
				break;


			case 'link' :
				if (DISPLAY_DATENSCHUTZ_ON_CHECKOUT == 'true') {
					return xtc_href_link('shop_content.php','coID=2');
				}
				break;


			case 'checkbox' :
				if (DISPLAY_DATENSCHUTZ_ON_CHECKOUT == 'true') {
					return '<input type="checkbox" value="dsg" name="dsg" id="dsg" class="radiobox" onclick="hitDSG()" />';
				}
				break;


			case 'stat' :
				if (DISPLAY_DATENSCHUTZ_ON_CHECKOUT == 'true') {
					return 1;
				} else {
					return 0;
				}
				break;
		}
	}

	function getAGB($which) {
		switch ($which) {
			case 'text' :
				if (DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
					if (GROUP_CHECK == 'true') {
						$group_check = "and group_ids LIKE '%c_" . $_SESSION['customers_status']['customers_status_id'] . "_group%'";
					}
					$shop_content_query = xtc_db_query("SELECT
																content_title,
																content_heading,
																content_text,
																content_file
																FROM " . TABLE_CONTENT_MANAGER . "
																WHERE content_group='3' " . $group_check . "
																AND languages_id='" . $_SESSION['languages_id'] . "'");
					$shop_content_data = xtc_db_fetch_array($shop_content_query);
					if ($shop_content_data['content_file'] != '') {
						if($shop_content_data['content_file'] == 'janolaw_agb.php') {
							include_once(DIR_FS_INC.'janolaw.inc.php');
							$conditions = JanolawContent('agb', 'txt');
						} else
							$conditions = '<iframe src="' . DIR_WS_CATALOG . 'media/content/' . $shop_content_data['content_file'] . '" width="100%" height="300"></iframe>';
					} else {
						$conditions = '<textarea name="blabla" cols="60" rows="10" readonly="readonly">' . strip_tags(str_replace('<br />', "\n", $shop_content_data['content_text'])) . '</textarea>';
					}
					return $conditions;
				}
				break;


			case 'link' :
				if (DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
					return xtc_href_link('shop_content.php','coID=3');
				}
				break;


			case 'checkbox' :
				if (DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
					return '<input type="checkbox" value="conditions" name="conditions" id="conditions" class="radiobox" onclick="hitAGB()"  />';
				}
				break;


			case 'stat' :
				if (DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
					return 1;
				} else {
					return 0;
				}
				break;
		}
	}

	function getFormUrl() {
		if (isset ($GLOBALS[$_SESSION['payment']]->form_action_url) && !$GLOBALS[$_SESSION['payment']]->tmpOrders) {
			$form_action_url = $GLOBALS[$_SESSION['payment']]->form_action_url;
		} else {
			$form_action_url = xtc_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');
		}
		$form_action_url = utf8_encode($form_action_url);

		return $form_action_url;
	}

	function getRevocation($which) {
		switch ($which) {
			case 'text' :
				if (DISPLAY_REVOCATION_ON_CHECKOUT == 'true') {
					if (GROUP_CHECK == 'true') {
						$group_check = "and group_ids LIKE '%c_" . $_SESSION['customers_status']['customers_status_id'] . "_group%'";
					}
					$shop_content_query = "SELECT
                                                content_title,
                                                content_heading,
                                                content_text,
                                                content_file
		                                   FROM
		                                   		" . TABLE_CONTENT_MANAGER . "
		                                   WHERE
		                                   		content_group='" . REVOCATION_ID . "' " . $group_check . "
		                                   AND
		                                   		languages_id='" . $_SESSION['languages_id'] . "'";

					$shop_content_query = xtc_db_query($shop_content_query);
					$shop_content_data = xtc_db_fetch_array($shop_content_query);

					if ($shop_content_data['content_file'] != '') {
						if($shop_content_data['content_file'] == 'janolaw_widerruf.php') {
							include_once(DIR_FS_INC.'janolaw.inc.php');
							$conditions = JanolawContent('widerrufsbelehrung', 'txt');
						} else
							$conditions = '<iframe src="' . DIR_WS_CATALOG . 'media/content/' . $shop_content_data['content_file'] . '" width="100%" height="300"></iframe>';
					} else {
						$conditions = '<textarea name="blabla" cols="60" rows="10" readonly="readonly">' . strip_tags(str_replace('<br />', "\n", $shop_content_data['content_text'])) . '</textarea>';
					}
					return $conditions;
				}
				break;


			case 'link' :
				if (DISPLAY_REVOCATION_ON_CHECKOUT == 'true') {
					return xtc_href_link('shop_content.php','coID='.REVOCATION_ID);
				}
				break;

			case 'checkbox' :
				if (DISPLAY_REVOCATION_ON_CHECKOUT == 'true') {
					return '<input type="checkbox" value="revocation" name="revocation" id="revocation" class="radiobox" onclick="hitRevocation()" />';
				}
				break;

			case 'stat' :
				if (DISPLAY_REVOCATION_ON_CHECKOUT == 'true') {
					return 1;
				} else {
					return 2;
				}
				break;
		}
	}

	function getIp () {
		if (SHOW_IP_LOG == 'true') {
			if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
				$customers_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
			} else {
				$customers_ip = $_SERVER["REMOTE_ADDR"];
			}
			return $customers_ip;
		} else {
			return '';
		}
	}

	function getProducts() {
		global $order;
		global $xtPrice;
		$data_products = '<div id="checkout_products_standart">';
		for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
			$data_products .= '<div'.(($i % 2 == 0) ? ' class="dunkel"' : '').'>';
			$html_update_qty = '';
			if (CHECKOUT_AJAX_PRODUCTS == 'true') {
				$html_update_qty = ' <td width="15%" valign="top"><nobr><a href="javascript:void(0);" onclick="updateProducts(\''.$order->products[$i]['id'].'\',\'minus\');">[-]</a> <a href="javascript:void(0);" onclick="updateProducts(\''.$order->products[$i]['id'].'\',\'plus\');">[+]</a> <a href="javascript:void(0);" onclick="removeProduct(\''.$order->products[$i]['id'].'\',\'minus\');"> <span style="color:#CC0000">[x]</span> </a></nobr></td>';
			}
			$img = xtc_db_fetch_array(xtc_db_query("SELECT products_image FROM products WHERE products_id = '".$order->products[$i]['id']."'"));
			if($img['products_image'] !='')
				$pImg = '<td width="25%"><img class="img_border" src="'.DIR_WS_THUMBNAIL_IMAGES.$img['products_image'].'" alt="'.$order->products[$i]['name'].'" /></td>';
			else
				$pImg = '';

			if ((isset ($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0)) {
				$attribut_products = '';
				for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) {
					$attribut_products .= '<div class="chk_attribute db fs85" style="line-height:30px">';
					if (CHECKOUT_AJAX_PRODUCTS == 'true')
						$attribut_products .= '<a class="fl mr10" href="javascript:void(0);" onclick="showSelect(\''.$i.$j.'\')"><img src="images/icons/pencil--arrow.png" style="vertical-align:middle;" alt="" /></a> ';
					$attribut_products .= '<span class="fl mr5">'.$order->products[$i]['attributes'][$j]['option'] . ':</span>
											<span id="atta_'.$i.$j.'">
												<span id="attt_'.$i.$j.'">' . $order->products[$i]['attributes'][$j]['value'] . '</span>
											</span>
											<span id="attd_'.$i.$j.'" style="display:none;">
												'.$this->getAllPossibleAttributes($order->products[$i]['id'], $order->products[$i]['attributes'][$j]['option_id'], $order->products[$i]['attributes'][$j]['value'], $i.$j).'
											</span>';
					$attribut_products	.='</div>';
				}
			}

			$data_products .= '<div id="product_'.$order->products[$i]['id'].'">
									<table width="100%" border="0" cellspacing="0" cellpadding="4" style="margin-bottom:12px;">
										<tr>'
										.$pImg.
										'<td width="50%" class="main" align="left" valign="top">
												<span id="qty_'.$order->products[$i]['id'].'">' . $order->products[$i]['qty'] . '</span>x
												' . '<strong>'.$order->products[$i]['name'] . '</strong><br />'.
												(ACTIVATE_SHIPPING_STATUS=='true'?'<span class="fs85"><nobr><em>' . SHIPPING_TIME . $order->products[$i]['shipping_time'] . '</em><nobr></span>':'').'<br /><br />'.
												$attribut_products.'
											</td>'
											. $html_update_qty .
											'<td width="10%" class="main" align="right" valign="top">
												<span id="price_'.$order->products[$i]['id'].'"><strong><nobr>' .
													$xtPrice->xtcFormat($order->products[$i]['final_price'], true) . '</nobr></strong>
												</span>
											</td>
										</tr>' . "\n";

			$data_products .= '' . "\n";

			if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
				if (sizeof($order->info['tax_groups']) > 1){
					require_once (DIR_FS_INC.'xtc_display_tax_value.inc.php'); 
					$data_products .= '            <td class="main" valign="top" align="right"><span id="tax_'.$order->products[$i]['id'].'">' . xtc_display_tax_value($order->products[$i]['tax']) . '</span>%</td>' . "\n";
				}
			}
			$data_products .= '</tr></table></div>' . "\n";
			$data_products .= '</div>';
		}
		$data_products .= '</div>';


		return $data_products;
	}

	function getAllPossibleAttributes($pid, $oid, $selected, $aid) {
		global $xtPrice;
		$dropdown = '<select id="att_'.$pid.$oid.'" name="att_'.$pid.$oid.'" size="1" onchange="updateAttributes(this.id, \''.$aid.'\')">';
		$query1 = xtc_db_query("SELECT * FROM ".TABLE_PRODUCTS_ATTRIBUTES." WHERE products_id = '".$pid."' AND options_id = '".$oid."'");

		if (xtc_db_num_rows($query1) <= 1) {
			// Only one Attribut
			$query1_array = xtc_db_fetch_array($query1);
			$query2 = xtc_db_query("SELECT * FROM ".TABLE_PRODUCTS_OPTIONS_VALUES." WHERE language_id = '".$_SESSION['languages_id']."' AND products_options_values_id = '".$query1_array['options_values_id']."'");
			$query2_array = xtc_db_fetch_array($query2);
			return $query2_array['products_options_values_name'];
		} else {
			// More than one attribute
			while ($query1_array = xtc_db_fetch_array($query1)) {
				$query2 = xtc_db_query("SELECT * FROM ".TABLE_PRODUCTS_OPTIONS_VALUES." WHERE language_id = '".$_SESSION['languages_id']."' AND products_options_values_id = '".$query1_array['options_values_id']."'");
				$query2_array = xtc_db_fetch_array($query2);
				// Check if selected
				$html_selected = '';
				if (html_entity_decode($query2_array['products_options_values_name']) == html_entity_decode($selected)) {
					$html_selected = ' selected';
				}
				$dropdown .= '<option value="'.$pid.'|'.$oid.'|'.$query2_array['products_options_values_id'].'"'.$html_selected.'>'.$query2_array['products_options_values_name'].' '.$query1_array['price_prefix'].' '.$xtPrice->xtcFormat($query1_array['options_values_price'], true).'</option>';
			}
		}
		$dropdown .= '</select>';
		return $dropdown;
	}

	function getStat($option) {
		$option = strtoupper($option);
		$query = xtc_db_query("SELECT configuration_value FROM ".TABLE_CONFIGURATION." WHERE configuration_key = 'CHECKOUT_SHOW_".$option."'");
		$query_array = xtc_db_fetch_array($query);
		if($query_array['configuration_value'] == 'true')
			return 1;
		else
			return 0;
	}

	function getAddresses($which) {
		if($which == 'shipping')
			$sess = 'sendto';
		elseif($which == 'payment')
			$sess = 'billto';

		$dropdown = '<select id="select_shipping_address" name="select_shipping_address" size="1" onchange="updateAddressBySelect(\''.$which.'\', this.value);">';
		$addresses_query = xtc_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from ".TABLE_ADDRESS_BOOK." where customers_id = '".$_SESSION['customer_id']."'");
		while ($addresses = xtc_db_fetch_array($addresses_query)) {
			$format_id = xtc_get_address_format_id($address['country_id']);
			$selected = '';
			if ($addresses['address_book_id'] == $_SESSION[$sess])
				$selected = ' selected';
			$short_address = xtc_address_format($format_id, $addresses, true, ' ', ', ');
			$strpos = strpos($short_address, ',', 25);
			if ($strpos != false)
				$short_address = substr($short_address, 0, $strpos+1).' ...';

			$short_addres = str_replace('ß', '&szlig;', $short_address);
			$short_addres = str_replace('ö', '&ouml;', $short_address);
			$short_addres = str_replace('ü', '&uuml;', $short_address);
			$short_addres = str_replace('ä', '&auml;', $short_address);
			$short_addres = str_replace('Ö', '&Ouml;', $short_address);
			$short_addres = str_replace('Ü', '&Uuml;', $short_address);
			$short_addres = str_replace('Ä', '&Auml;', $short_address);

			$dropdown .= '<option value="'.$addresses['address_book_id'].'"'.$selected.'>'.$short_address.'</option>';
		}
		$dropdown .= '</select>';
		return $dropdown;

	}

	function getEditAddressButton($which) {
		return '<a href="javascript:void(0);" onclick="editAddress(\''.$which.'\')">'.xtc_image_button('button_checkout_edit.gif',IMAGE_BUTTON_EDIT).'</a>';
	}

	function getSaveAddressButton($which) {
		return '<a href="javascript:void(0);" onclick="updateAddress(\''.$which.'\')">'.xtc_image_button('button_checkout_save.gif',IMAGE_BUTTON_SAVE).'</a>';
	}

	function getBackButton($which) {
		return '<a href="javascript:void(0);" onclick="cancelAddress(\''.$which.'\')">'.xtc_image_button('button_back.gif',IMAGE_BUTTON_BACK).'</a>';
	}

	function getSaveModuleButton($which) {
		if($which == 'payment')
			return '<a href="javascript:void(0);" onclick="updatePaymentModule()">'.xtc_image_button('button_checkout_save.gif',IMAGE_BUTTON_SAVE,'id="button_save_payment"').'</a>';
		elseif($which == 'shipping')
			return '<a href="javascript:void(0);" onclick="updateShippingModule()">'.xtc_image_button('button_checkout_save.gif',IMAGE_BUTTON_SAVE,'id="button_save_shipping"').'</a>';
	}

	function newAddressPossible() {
		$addresses_query = xtc_db_query("select address_book_id, entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from ".TABLE_ADDRESS_BOOK." where customers_id = '".$_SESSION['customer_id']."'");
		$count = xtc_db_num_rows($addresses_query);
		if ($count >= MAX_ADDRESS_BOOK_ENTRIES)
			return 0;
		else
			return 1;
	}

	function isVirtual() {
		global $order;
		$virtual = 0;
		if ($order->content_type == 'virtual' || ($order->content_type == 'virtual_weight') || ($_SESSION['cart']->count_contents_virtual() == 0)) {
			unset($_SESSION['shipping']); 
			#unset($_SESSION['payment']);
			$virtual = 1;
		}
		return $virtual;
	}

	function getStates($country_id) {
		if (ACCOUNT_STATE == 'true') {
			$zone_id = 0;
			$check_query = xtc_db_query("select count(*) as total from ".TABLE_ZONES." where zone_country_id = '".$country_id."'");
			$check = xtc_db_fetch_array($check_query);
			$entry_state_has_zones = ($check['total'] > 0);
			if ($entry_state_has_zones) {
				$dropdown = '<select size="1">';
				$dropdown .= '</select>';
			}
		} else
			return false;
	}

	function convertToVars($query_string) {
		$vars = array();
		if(strpos($query_string, '&') === false) {
			$string = str_replace('"', '', stripslashes($query_string));
			$string = str_replace('{', '', $string);
			$string = str_replace('}', '', $string);

			$exploded = explode(',', $string);

			for($i=0; sizeof($exploded) > $i; $i++) {
				$trennen = explode(':', $exploded[$i]);
				if($trennen[0] != '' && $trennen[1] !='')
					$vars[$trennen[0]] = $trennen[1];
			}

		} else {
			if (!is_array($query_string)) {
				$arr_vars = explode('&',$query_string);
				foreach ($arr_vars as $value) {
					$arr_vars2 = explode('=',$value);
					$vars[$arr_vars2[0]] = utf8_decode(urldecode($arr_vars2[1]));
				}
			} else {
				reset($query_string);
				while (list($key, $value) = each ($query_string))
					$vars[$key] = utf8_decode($value);
			}
		}
		return $vars;
	}

	function isFreeShipping($order, $xtPrice) {
		if (defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true')) {
			switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
				case 'national' :
					if ($order->delivery['country_id'] == STORE_COUNTRY)
						$pass = true;
					break;
				case 'international' :
					if ($order->delivery['country_id'] != STORE_COUNTRY)
						$pass = true;
					break;
				case 'both' :
					$pass = true;
					break;
				default :
					$pass = false;
					break;
			}

			$free_shipping = false;
			if (($pass == true) && ($order->info['total'] - $order->info['shipping_cost'] >= $xtPrice->xtcFormat(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER, false, 0, true))) {
				$free_shipping = true;

			}
		} else
			$free_shipping = false;
		return $free_shipping;
	}

	function getTaxID($id) {
		$cart_products = $_SESSION['cart']->get_products();
		for ($i=0; $i<count($cart_products); $i++) {
			if ($cart_products[$i]['id'] == $id) {
				$tax_class_id = $cart_products[$i]['tax_class_id'];
				break;
			}
		}
		return $tax_class_id;
	}

	function getShippingBlock($xtPrice) {
		global $shipping_modules;
		global $order;
		global $total_weight;
		global $total_count;
		global $shipping_compatible;

		if (!is_object($shipping_modules)) {
			require (DIR_WS_CLASSES.'shipping.php');
			$shipping_modules = new shipping;
			$free_shipping = $this->isFreeShipping($order, $xtPrice);
			if($free_shipping)
				include (DIR_WS_LANGUAGES.$_SESSION['language'].'/modules/order_total/ot_shipping.php');
		}
		$quotes = $shipping_modules->quote();

		// SHIPPING STUFF

		$module_smarty = new Smarty;
		if (xtc_count_shipping_modules() > 0) {
			$showtax = $_SESSION['customers_status']['customers_status_show_price_tax'];

			$radio_buttons = 0;
			#loop through installed shipping methods...
			$something_checked = false;

			for ($i = 0, $n = sizeof($quotes); $i < $n; $i ++) {
				if (!isset ($quotes[$i]['error'])) {
					for ($j = 0, $n2 = sizeof($quotes[$i]['methods']); $j < $n2; $j ++) {
						# set the radio button to be checked if it is the method chosen
						$quotes[$i]['methods'][$j]['radio_buttons'] = $radio_buttons;
						$checked = (($quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']['id'] || $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']) ? true : false);
						if (($checked == true) || ($n == 1 && $n2 == 1)) {
							$quotes[$i]['methods'][$j]['checked'] = 1;
							$something_checked = true;
						}

						if (($n > 1) || ($n2 > 1)) {
							if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0)
								$quotes[$i]['tax'] = '';
							if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0)
								$quotes[$i]['tax'] = 0;

							$quotes[$i]['methods'][$j]['price'] = $xtPrice->xtcFormat(xtc_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax']), true, 0, true);
							$quotes[$i]['methods'][$j]['radio_field'] = xtc_draw_radio_field('shipping', $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'], $checked, 'onclick="if (this.checked) { shippingShowOrHide(\'smodule'.$radio_buttons.'\'); this.checked=true; return true; }"').xtc_draw_hidden_field($quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'].'_num', $radio_buttons+1);
							$quotes[$i]['methods'][$j]['value_id'] = $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'];

						} else {
							if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0) {
								$quotes[$i]['tax'] = 0;
							}
							if ((isset ($quotes[$i]['methods'][$j]['title'])) && (isset ($quotes[$i]['methods'][$j]['cost']))) {
								$_SESSION['shipping'] = array ('id' => $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'], 'title' => (($this->isFreeShipping($order, $xtPrice) == true) ? $quotes[$i]['methods'][$j]['title'] : $quotes[$i]['module'].' ('.$quotes[$i]['methods'][$j]['title'].')'), 'cost' => $quotes[$i]['methods'][$j]['cost']);
							}
							$quotes[$i]['methods'][$j]['value_id'] = $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'];
							$quotes[$i]['methods'][$j]['price'] = $xtPrice->xtcFormat(xtc_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax']), true, 0, true).xtc_draw_hidden_field('shipping', $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id']).xtc_draw_hidden_field($quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'].'_num', $radio_buttons+1);
						}
						$radio_buttons ++;
					}
				}
			}

			if ($something_checked == false && !empty($_SESSION['shipping']['id'])) {
				unset($_SESSION['shipping']);
				$shipping_compatible = false;
			}
			$module_smarty->assign('module_content', $quotes);
			$module_smarty->assign('module_choose', CHECKOUT_SHIPPING_CHOOSE);
			$module_smarty->caching = 0;
			if (CHECKOUT_VIEW == 'Dropdown')
				$shipping_block = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/checkout_shipping_block_dropdown.html');
			else
				$shipping_block = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/checkout_shipping_block.html');
			return $shipping_block;
		}
	}

	function getPaymentBlock($xtPrice, $payment_modules) {
		global $payment_compatible;
		global $order;
		$module_smarty = new Smarty;

		$something_checked = false;
		$selection = $payment_modules->selection();
				for($i = 0, $n = count($order->products); $i < $n; $i++ ){
			$pID = xtc_get_prid($order->products[$i]['id']);
			$sperre_query = xtc_db_query("SELECT
											products_forbidden_payment
										FROM
											" . TABLE_PRODUCTS . "
										WHERE
											products_id = '".$pID."' ");

			if(xtc_db_num_rows($sperre_query)) {
				$sperre_values = xtc_db_fetch_array($sperre_query);
				if(!empty($sperre_values['products_forbidden_payment'])) {
					if(strpos($sperre_values['products_forbidden_payment'], '|')) {
						$value = explode('|', $sperre_values['products_forbidden_payment']);
						for($v = 0; $v <= sizeof($value); $v++)
							$tmp[] = $value[$v];
					} else
						$tmp[] = $sperre_values['products_forbidden_payment'];
				}
			}
		}

		$n = sizeof($selection);
		if(is_array($tmp)) {
			foreach($tmp AS $paymentmodule => $value) {
				for ($i = 0; $i <= $n; $i++) {
					$name = explode('.', $value);
					if($selection[$i]['id'] == $name[0])
						unset($selection[$i]);
				}
			}
		}
		$radio_buttons = 0;
		for ($i = 0;$i < $n; $i++) {
			$selection[$i]['radio_buttons'] = $radio_buttons;
			if (($selection[$i]['id'] == $_SESSION['payment']) || ($n == 1)) {
				$selection[$i]['checked'] = 1;
				$something_checked = true;
			}
			if (empty($selection[$i]['module_cost']) && isset($GLOBALS[$selection[$i]['id']]->cost))
				$selection[$i]['module_cost'] = CHECKOUT_PAYMENT_DUE;

			if (sizeof($selection) > 1) {

				$selection[$i]['selection'] = xtc_draw_radio_field('payment', $selection[$i]['id'], ($selection[$i]['id'] == $_SESSION['payment']), 'onclick="if (this.checked) { paymentShowOrHide(\'pmodule_'.$selection[$i]['id'].'\'); this.checked=true; return true; }"').xtc_draw_hidden_field($selection[$i]['id'].'_num', $i+1);
			} else {
				$only_one = 1;
				$selection[$i]['selection'] = xtc_draw_hidden_field('payment', $selection[$i]['id']).xtc_draw_hidden_field($selection[$i]['id'].'_num', $i+1);

				if (!is_array($selection[$i]['fields']) && !isset($selection[$i]['fields'])) {
					if ($_SESSION['payment'] != 'no_payment') $_SESSION['payment'] = $selection[$i]['id'];
				} else {
					unset($_SESSION['payment']);
					$something_checked = false;
					$selection[$i]['checked'] = 0;
				}
			}
			$selection[$i]['value_id'] = $selection[$i]['id'];

			if (isset ($selection[$i]['error'])) {

			} else
				$radio_buttons++;
		}

		if ($something_checked == false && !empty($_SESSION['payment'])) {
			unset($_SESSION['payment']);
			$payment_compatible = false;
		}

		// LUUPAY SECOND STEP
		if (is_object($GLOBALS['luupws']) && $GLOBALS['luupws']->enabled == true) {
			global $xajax_step;
			$xajax_step = 'step2';
			$luupay_selection = $GLOBALS['luupws']->selection();
			unset($xajax_step);
			$luupay_smarty = new Smarty;
			$luupay_smarty->assign('module_data', $luupay_selection);
			if (CHECKOUT_VIEW == 'Dropdown') {
				$luupay_block = $luupay_smarty->fetch(CURRENT_TEMPLATE . '/module/checkout_payment_block_luupay_step2_dropdown.html');
			} else {
				$luupay_block = $luupay_smarty->fetch(CURRENT_TEMPLATE . '/module/checkout_payment_block_luupay_step2.html');
			}
			$luupay_smarty->caching = 0;
		}
		$module_smarty->assign('module_content', $selection);
		$module_smarty->assign('module_choose', CHECKOUT_PAYMENT_CHOOSE);
		$module_smarty->assign('luupay_step2', $luupay_block);
		$module_smarty->assign('xajax', 1);
		$module_smarty->assign('only_one', $only_one);
		$module_smarty->caching = 0;
		if (CHECKOUT_VIEW == 'Dropdown')
			$payment_block = $module_smarty->fetch(CURRENT_TEMPLATE . '/module/checkout_payment_block_dropdown.html');
		else
			$payment_block = $module_smarty->fetch(CURRENT_TEMPLATE . '/module/checkout_payment_block.html');

		return $payment_block;
	}

	function getTotalBlock($order, $order_total_modules, $xtPrice) {
		if (MODULE_ORDER_TOTAL_INSTALLED)
			$total_block = $order_total_modules->output();
		return $total_block;
	}
}
?>